import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
//语言包导入
// let Chinese = require('@/static/language/ch.js').message
// let English = require('@/static/language/en.js').message

const lans = uni.getStorageSync('lan');
const token = uni.getStorageSync('token');
const jti = uni.getStorageSync('lan');
export default new Vuex.Store({
	state: {
		// #ifdef H5
		token: token,
		// #endif
		// #ifdef MP 
		token: token || '',
		// #endif
		userinfo: {},
		mapkey: 'f8150a21163387878e99d4bd3cb0a81f', 
		message: [],
		// baseUrl: 'http://192.168.2.149:8082', 
		baseUrl: 'http://192.168.2.246:8082',
		appNmae: '信通',
		versions: '1.0.0',
		// h5baseUrl:'/api'
		Transfer: '',
		socketTask: null,//连接
		socketUrl: 'ws://192.168.2.149:8082',
		
	},
	getters: {
		socketTask:state => state.socketTask,
		mapkey: state => state.mapkey,
		token: state => state.token,
		userinfo: state => state.userinfo,
		lan: state => state.lan,
		message: state => {
			let message = state.message;
			if (state.lan == 'en') {
				message = English
			} else {
				message = Chinese
			}
			return message;
		},
	},
	actions: {


	},
	mutations: { 
		
		//登录
		login(state, {
			token,
			userinfo
		}) {
			state.token = token
			state.userinfo = userinfo
			uni.setStorageSync('token', token);

		},
		saveInfo(state, {
			userinfo
		}) {
			state.userinfo = userinfo
		},
		//注销
		logout(state) {
			state.token = ''
			state.userinfo = []
			uni.removeStorageSync('token');
		},
		setThemeColor(state, val) {
			state.message = val;
			uni.setStorageSync('language', val);
		},
		to(state, url) {
			console.log(url);
			uni.showToast({
				title: "加载中",
				icon: 'loading',
			})
			setTimeout(function() {
				uni.navigateTo({
					url: url,
					success: res => {},
					fail: () => {},
					complete: () => {}
				});
			}, 400);
		}
	},
})